//
//  CategoryHome.swift
//  swiftUilearn
//
//  Created by fengliulin on 2024/3/28.
//

import SwiftUI

struct CategoryHome: View {
    @Environment(ModelData.self) var modelData
    @State private var showingProfile = false
    
    var body: some View {
        NavigationSplitView {
            List {
                PageView(pages: modelData.features.map { FeatureCard(landmark: $0) })
                                    .listRowInsets(EdgeInsets())


                                ForEach(modelData.categories.keys.sorted(), id: \.self) { key in
                                    CategoryRow(categoryName: key, items: modelData.categories[key]!)
                                }
                                .listRowInsets(EdgeInsets())
            }
            .listStyle(.inset)
                .navigationTitle("精选")
                .toolbar {
                    Button {
                        showingProfile.toggle()
                    }label: {
                        Label("User Profile", systemImage: "person.crop.circle")
                    }
                }
                .sheet(isPresented: $showingProfile) {
                                ProfileHost()
                                    .environment(modelData)
                            }
        } detail: {
            Text("Detail")
        }
    }
}

#Preview {
    CategoryHome()
        .environment(ModelData())
}
